# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libvirt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.9.0
pkgrel=1
pkgdesc="Windows libvirt virtualization library (mingw-w64)"
arch=('any')
url="https://libvirt.org"
license=('LGPL2')
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-portablexdr")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python3")
options=('strip' 'staticlibs')
source=(https://libvirt.org/sources/${_realname}-${pkgver}.tar.xz
        001-fix-not-supported-authenticate-method.patch)
sha256sums=('3496d2e1d988185de013b2a9d2e8824458afd85aa7cd050283a59b3d78978939'
            '4635fd04e596879186b74ef9ddbacf64f6058e32bfd8d8376e1b7fa7838f679b')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-not-supported-authenticate-method.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  CPPFLAGS+=" -D_WIN32_WINNT=0x0501"
  # https://github.com/msys2/MINGW-packages-dev/pull/6
  LDFLAGS+=" -fstack-protector"

  PYTHON="${MINGW_PREFIX}/bin/python3" \
  ../${_realname}-${pkgver}/configure \
    --enable-shared \
    --enable-static \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --without-xen \
    --without-qemu \
    --without-openvz \
    --without-lxc \
    --without-vbox \
    --without-xenapi \
    --without-sasl \
    --without-avahi \
    --without-polkit \
    --without-libvirtd \
    --without-uml \
    --without-phyp \
    --without-esx \
    --without-hyperv \
    --without-vmware \
    --without-parallels \
    --without-netcf \
    --without-audit \
    --without-dtrace \
    --enable-expensive-tests
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
